<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>新增公告</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
  <script src="/static/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<form class="layui-form   layui-form-pane" action="">
  <!-- 公告内容 -->
  <div class="layui-form-item">
    <label class="layui-form-label">公告内容</label>
    <div class="layui-input-block">
      <input type="text" name="content" value="" required lay-verify="required"
             placeholder="请输入公告内容" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>

</form>

<script>
  layui.use(['form', 'laydate'], function () {
    $ = layui.jquery;
    var form = layui.form

    //监听提交
    form.on('submit(formDemo)', function (data) {
      $.ajax({
        url: '/annoAdd',
        method: 'post',
        data: data.field, // JSON.stringify(data.field),
        dataType: 'json',
        success: function (data) {
          if (data.code == "0") {
            parent.layer.msg("新增成功", {
              icon: 6,
              time: 500
            }, function () {
              // 重新加载父页面
              parent.location.reload();
            });
            setTimeout(function () {
              var index = parent.layer.getFrameIndex(window.name); // 操作父页面
              parent.layer.close(index);
            }, 500);

          } else {
            layer.msg("新增失败");
          }
        }
      })
      return false;
    })
  })
</script>

</body>
</html>
